Repository navigation
Convert Dolby Vision profile 7 to 8.1 on devices without a profile 7 decoder - #2017
Conversation
|
I tested it with a Homatics Box R 4K plus, it worked fine for me. So all hybrid movies played fine after deleting the above. |
|
Thanks for testing on the Homatics — good to have it confirmed on a second S905X4 box. The hybrid file is a separate thing from Profile 7, and the flag is working as intended: I'd rather not fold that into this PR: the Jellyfin team declined to change the classification |
|
A short status, in case it helps with review. Since the PR was opened it has been run by two It is behind an experimental toggle, off by default, so it changes nothing for anyone who does not |
aae72ba to
e7adf63
Compare
Profile 7 is HDR10 compatible HEVC plus an RPU in NAL unit type 62 and an enhancement layer in type 63. A decoder which lists profile 8 but not profile 7 takes such a stream but does not switch the display into Dolby Vision for it, so the picture comes out as the HDR10 base layer. Kodi, Vimu and Dune play these files in Dolby Vision on the same hardware by rewriting the RPU into its profile 8.1 form and dropping the enhancement layer; nothing is re-encoded. DolbyVisionProfile7Filter does that as an entry in the BitstreamFilter list: every access unit is copied without its type 63 units into a direct scratch buffer, libdovi (ExoplayerHdrUtils, MIT, already on Maven Central) rewrites the RPU there, and the result is copied back only once it has succeeded and fits, so a refused access unit reaches the decoder untouched. Access units without an RPU, or whose RPU is not profile 7, pass through. media3 chooses the decoder by Format.codecs, and a decoder without profile 7 answers "not supported" to dvhe.07; with decoder fallback on, playback then lands on whichever decoder is first in the list. So DolbyVisionProfile7ExtractorsFactory advertises profile 7 video tracks as dvhe.08 at the extractor, which also sets MediaFormat.KEY_PROFILE right. Both halves, and direct play of profile 7 in the device profile, are switched on by one decision: the experimental preference is on, the device lists no profile 7 decoder, and it does list a profile 8 one. A device which decodes profile 7 itself keeps the enhancement layer the conversion would throw away. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
e7adf63 to
b0c318d
Compare
|
Rebased onto #1644 removed the ktlint is clean and all 422 unit tests pass locally. Update: re-tested the rebased branch on a Homatics Box R 4K Plus (Amlogic, Android 14) with an LG OLED, built together with #2065 on top of
|
damontecres
left a comment
There was a problem hiding this comment.
This looks good. I think have a decent grasp on how this works.
I pushed a few minor changes. It doesn't look like exoplayerhdrutils ship consumer proguard rules., so I also pushed a proguard rule to keep the native class.
|
Tested development build, google 4k streamer. Successful displayed correctly using the new feature. |
Description
On Amlogic boxes (S905X4 and similar) Dolby Vision Profile 7 does not play as Dolby Vision.
The server transcodes it, or, with "Direct play Dolby Vision Profile 7" switched on by hand, the
decoder answers
NoSupportand fallback ends in HDR10. Devices with a native Profile 7 decoder,such as the Shield, are not affected and nothing changes for them.
This PR converts Profile 7 to 8.1 on the fly. It has two halves and one decision:
util/DolbyVisionProfile7Filter.kt— an entry in theBitstreamFilterlist from Add option to prefer Dolby Vision over HDR10+ on hybrid videos #1876. Itdrops the enhancement layer (NAL 63) and has libdovi rewrite the RPU to 8.1. The decoder gets
either a fully converted access unit or an untouched one: with no RPU, an RPU that is not
Profile 7, a libdovi refusal, or a result that does not fit the buffer, the bytes stay as they
were. If the native library fails to load, the filter switches itself off for good with a
single log line. Counts of converted / passed through / refused access units are logged on
release().util/DolbyVisionProfile7ExtractorsFactory.kt— rewrites onlyFormat.codecsof advhe.07.xx/dvh1.07.xxvideo track to…08.xx. Without it nothing works: media3 picks thedecoder by this string, and with
dvhe.07every Dolby Vision decoder on Amlogic answersNoSupport. Samples are not touched. DRM tracks are not rewritten, since their samples bypassthe filter. It wraps
withAssMkvSupportfrom the outside, so libass's Matroska replacement iscovered too.
util/DolbyVisionProfile7Conversion.isWanted()— one condition for all of it: experimentalsettings are on, and the preference is on, and the device does not list a Profile 7
decoder, and it does list a Profile 8 one (new
supportsHevcDolbyVisionProfile8()inMediaCodecCapabilitiesTest). The same condition enables direct play ofDOVIWithELinDeviceProfileService, so the manual toggle is not needed.The preference
convertDolbyVisionProfile7is proto field 6 in the experimental settings, off bydefault. In
WholphinRenderersFactorythe filter comes first in the list, followed by the HDR10+masking from #1876.
Dependency:
com.suyashbelekar:exoplayerhdrutils:0.4.1— MIT, on Maven Central, with thenative library for
arm64-v8a/armeabi-v7a/x86_64, exactly the ABIs this app splits on.Only
LibDoviis used. The library'sHevcFrameTransformeris not: it decides from the firstframe and throws on a frame without an RPU. The library pulls in media3 1.10.1 transitively;
Gradle resolves it to the project's 1.11.1.
On taking the library as a whole (#1540): as already noted in #244, the published releases
of the library do not rewrite the codec string, which on Amlogic is a silent failure — the
conversion reports success and the display stays in HDR10. The fix lives in an unmerged branch
of the library. This PR does not depend on it.
What this PR does not do. The enhancement layer is dropped; that is the price of the
conversion, which is why devices with a native Profile 7 decoder are left alone.
BlockAdditional(an enhancement layer outside the stream) is not read — like the rest ofWholphin today — so such a file stays HDR10, as it is now.
Related issues
Closes #244
Builds on #1876 (the
BitstreamFilterlist). Related to #1540. @fanni42 asked for exactly this onan S905X4 in #1876.
Testing
Hardware — a debug build of this branch, Homatics box (Amlogic S905X4, Android 14) + LG BX,
Jellyfin 12.1.0, a Profile 7 FEL remux with the enhancement layer in band, played from the start
for 39 seconds. Only the new preference was switched on; manual "Direct play Dolby Vision
Profile 7" was off:
DirectPlaydvhe.07.06→dvhe.08.06c2.amlogic.dolby-vision.dvhe.decoder;dav1anddvavanswerNoSupport; noFormat exceeds…onHdrInfoChange=30.4 s after the decoder was created;hdmi_hdr_statusSDR →DolbyVision-Std→ SDR after exit; Dolby Vision badge on the TVThe same measurement on the branch before the rebase (library
0.3.0, 16 September) gave thesame result with 1200 access units over 45 seconds.
Unit tests — 25, on the JVM without the native part:
DolbyVisionProfile7FilterTest(14) — a fake rewriter on a direct buffer: offset ≠ 0,position/limit untouched, every "bytes stay as they were" branch, three-byte start codes,
UnsatisfiedLinkErrortried once;DolbyVisionProfile7ExtractorsFactoryTest(5, mockk) — only the video track is rewritten;DolbyVisionProfile7ConversionTest(6) — codec strings, DRM,dvh1.CI in my fork ran on this branch plus a debug signing commit:
pre-commit,testDefaultDebugUnitTestandassembleDefaultDebugare all green. The hardware measurementabove is that build.
Screenshots
The only UI change is one toggle in the experimental settings.
AI or LLM usage
The code was written with Claude (Claude Code): the filter, the extractor wrapper, the condition
and the tests. I reviewed every line and can explain it. It was tested with the unit tests and
the hardware measurement above. This description was written by me in Russian and translated
into English with the same assistant.